

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>编辑资源</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
<link rel="stylesheet"
	href="/admin/std/dist/layuiadmin/layui/css/layui.css" media="all">

<link rel=stylesheet href="/html/lib/code/doc/docs.css">

<link rel="stylesheet" href="/html/lib/code/lib/codemirror.css">
<link rel="stylesheet" href="/html/lib/code/addon/hint/show-hint.css">

<style>
.CodeMirror {
	border-top: 1px solid #888;
	border-bottom: 1px solid #888;
	height: 100%;
}
</style>
</head>
<body>
	<div class="layui-form" lay-filter="layuiadmin-app-form-list"
		id="layuiadmin-app-form-list" style="padding: 20px 30px 0 0;">
		<div class="layui-form-item ">
			<input type="hidden" name="id" id="id"/>
		</div>
		<div class="layui-form-item "></div>
			<textarea id="code" name="code" class="layui-textarea">
			</textarea>
		</div>
	</div>
	<script src="/html/lib/code/lib/codemirror.js"></script>
	<script src="/html/lib/code/addon/hint/show-hint.js"></script>
	<script src="/html/lib/code/addon/hint/xml-hint.js"></script>
	<script src="/html/lib/code/addon/hint/html-hint.js"></script>
	<script src="/html/lib/code/mode/xml/xml.js"></script>
	<script src="/html/lib/code/mode/javascript/javascript.js"></script>
	<script src="/html/lib/code/mode/css/css.js"></script>
	<script src="/html/lib/code/mode/htmlmixed/htmlmixed.js"></script>
	<script src="/html/layui/layui.js"></script>

	<script>
		var editor=null;
		layui.config({
			base : '/html/' //静态资源所在路径
		}).extend({
			index : 'lib/index' //主入口模块
		}).use([ 'index', 'form' ], function() {
			editor =CodeMirror.fromTextArea(document.getElementById("code"), {
				lineNumbers : true,
				lineWrapping : true,
				mode : "text/html",
				extraKeys : {
					"Alt-/" : "autocomplete"
				}
			//,value: document.documentElement.innerHTML
			});
			function getQueryVariable(variable) {
				var query = window.location.search.substring(1);
				var vars = query.split("&");
				for (var i = 0; i < vars.length; i++) {
					var pair = vars[i].split("=");
					if (pair[0] == variable) {
						return pair[1];
					}
				}
				return (false);
			}
			
			
			
			
			var $ = layui.$, form = layui.form;
			var id = getQueryVariable("id");
			if (id) {
				$("#id").val(id);
				$.ajax({
					async : true,
					"url" : "/api/resource/version/get" + "?id=" + id,
					"global" : false,
					"type" : "GET",
					"dataType" : "json",
					"timeout" : "60000",
					"traditional" : true,
					"success" : function(a, b, c) {
						if (a.v[0].content) {
							editor.setValue(a.v[0].content)
						}

						//parent.layui.table.reload('LAY-app-content-list'); //重载表格
						//parent.layer.close(index); //再执行关闭 
					},
					"error" : function(err, msg, code) {
						return false;
					}
				});
			}
			layui.form.on("submit(layuiadmin-app-form-edit)", function(i) {
				editContent(i)
			})
			function editContent(i){
				var field = i.field;
				field.config=editor.getValue();
				layui.$.ajax({
					async : true,
					"url" : "/api/resource/modData",
					"global" : false,
					"type" : "POST",
					"contentType": "application/json; charset=utf-8",
					"dataType" : "json",
					"timeout" : "60000",
					"data" : JSON.stringify(field),
					"traditional":true,
					"success" : function(a,b,c){
						layer.msg('修改资源成功！');
						//parent.layui.table.reload('LAY-app-content-list'); //重载表格
						//parent.layer.close(e); //再执行关闭 
					},
					"error" : function(err, msg, code) {
						return false;
					}
				});
			}
			
		})
	</script>
</body>
</html>
